/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			pagedata.h
  \date			Aug 2011
  \author		TNick

  \brief		Contains the definition for PageData class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n
 Please read ReadMe.txt and Licence.txt in root folder @n
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @n

*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PAGEDATA_INC__
#define __PAGEDATA_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

class       PageData;

#include    <QDebug>

#include    <QDate>
#include    <QTime>
#include    <QDesktopServices>


#include    <generic/cc_l2dn.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

class       tmp_cnct    : public QObject {
    Q_OBJECT

public:
    PageData    *   pd;
    QString         result;
    bool            b_waiting;

    virtual         ~tmp_cnct() {};

public slots:
    void            finishReadPage    (void);

};

/// representing one page that was extracted and shuld be part of the chain
/**
*	The string (name) property of CC_L2DN is used to store the URL
*/
class PageData : public CC_L2DN 		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */


    /** @name flags for this class     */
    //@{

    /// defines various flags valid for uFlg member
    enum		FLG		{
        NONE = 0,		/**< no flag is set */
        WAIT_FOR_PD = 0x0001,	/**<  */
        FLAG_2 = 0x0002,	/**<  */
        FLAG_3 = 0x0004,	/**<  */
        FLAG_4 = 0x0008,	/**<  */

        TOPVAL			/**< values above and equal are invalid */
    };

    //@}



	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:


    /** @name flags for this class     */
    //@{

    /// various flags
    FLG             flags;

    //@}



	/// display name for this page
	QString     display_name;

	/// the day when this page was retrieved
	QDate       retr_date;

	/// the time when this page was retrieved
	QTime       retr_time;

    /// used in chaining filtered pages
	PageData *  p_next_pg;

    /// path to cached file content
    QString     cached_file_name;



	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/// constructor;
	PageData		(
		QString the_Url, QString the_displ_name, CC_HDL2DN* pFth = 0);

	/// destructor;
	virtual				~PageData		(void);


	/// set the name
    inline void         setDisplName        (QString new_name)
	{ display_name = new_name; }
	/// get the name
    inline QString      displName           (void)
	{ return display_name; }

	/// set the URL
    inline void         setURL              (QString new_url)
	{ setName(new_url); }
	/// get the URL
    inline QString      URL                 (void)
	{ return Name(); }

	/// the date when this was retrieved
    inline QString      dateOfRetrieval     (void)
	{ return retr_date.toString() + " " + retr_time.toString(); }


	/// set the next page in the chain
    inline void         setNextFltPage      (PageData* new_page)
	{ p_next_pg = new_page; }
	/// get the next page in the chain
    inline PageData*    nextFltPage       (void)
	{ return p_next_pg; }


	inline PageData *   next            (void)
	{ return static_cast<PageData *>(CC_L2DN::next()); }

	inline PageData *   prev            (void)
	{ return static_cast<PageData *>(CC_L2DN::prev()); }

    /// retrieves the content of the page from cache
    /**
      * Failure to get the page results in QString() being returned
      */
    QString             pageContent     (void);



    /** @name flags for this class     */
    //@{

    /// set
    inline void     setWaitingForPD     (bool b_set)
    {
        if (b_set) flags = (FLG)(flags | WAIT_FOR_PD);
        else flags = (FLG)(flags & (~WAIT_FOR_PD));
    }
    /// get
    inline bool     waitingForPD         (void)
    { return ((flags & WAIT_FOR_PD) != 0); }

    //@}

	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
    //


};	/*	class PageData	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __PAGEDATA_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
